package com.joelemon.mockinfluxdbdata.enums;

import com.baomidou.mybatisplus.annotation.EnumValue;
import com.baomidou.mybatisplus.annotation.IEnum;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;
import lombok.Getter;

import java.util.Objects;

/**
 * @Description: 通用标记位
 * @Author: HJY
 * @Date: 2023/7/10
 */
public enum CommonFlag implements IEnum<Integer> {
    NO(0),
    YES(1),
    ;

    @Getter
    @EnumValue
    @JsonValue
    private Integer value;
    CommonFlag(Integer value) {
        this.value = value;
    }

    @JsonCreator
    public static CommonFlag of(Integer val) {
        for (CommonFlag type : values()) {
            if (type.getValue().equals(val)) {
                return type;
            }
        }
        return null;
    }

    /**
     * 判断是否相等
     * @param obj
     * @return
     */
    public boolean isEqual(Object obj) {
        if (Objects.nonNull(obj)) {
            if (String.valueOf(obj).length() == 1 &&
                    String.valueOf(obj).startsWith(value.toString())) {
                return true;
            }
        }
        return false;
    }

}
